package com.geospatial.algorithm.controller;

import com.geospatial.algorithm.service.index.GeoHashService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@Api(value = "/indexAlgorithm/geohash")
@RequestMapping("/indexAlgorithm/geohash")
@RestController
public class IndexGeoHashAlgorithmController {
    @Autowired
    private GeoHashService geoHashService;

    @RequestMapping(value = "/encodeGeoHash",method = RequestMethod.GET)
    @ApiOperation(value = "经纬度转换geohash", notes = "", code = 200, produces = "")
    public String encodeGeoHash(@ApiParam(name = "longitude",value = "经度", required = true) @RequestParam double longitude,
                                @ApiParam(name = "latitude", value = "纬度",required = true) @RequestParam double latitude) {
        String geohash = geoHashService.encodeGeoHash(longitude,latitude);
        return geohash;
    }

    @RequestMapping(value = "/decodeGeoHash",method = RequestMethod.GET)
    @ApiOperation(value = "geohash换经纬度转", notes = "", code = 200, produces = "")
    public Map decodeGeoHash(@ApiParam(name = "geohash",value = "geohash串", required = true) @RequestParam String geohash) {
        Map lonlat = geoHashService.decodeGeoHash(geohash);
        return lonlat;
    }

    @RequestMapping(value = "/calculateAdjacent",method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value = "计算临近geohash", notes = "", code = 200, produces = "")
    public String calculateAdjacent(@ApiParam(name = "geohash",value = "geohash串", required = true) @RequestParam String geohash,
                                @ApiParam(name = "direction",value = "top,left,right,bottom", required = true) @RequestParam String direction) {
        return geoHashService.calculateAdjacent(geohash, direction);
    }
}
